#!/usr/bin/env coffee

import chalk from 'chalk'
import * as DIR from '../const/dir'
import Database from 'better-sqlite3'
import {join} from 'path'
import {mkdirSync,existsSync,readFileSync} from 'fs'

DB_PATH = join(DIR.DB,'sql')

is_new = not existsSync DB_PATH

if is_new
  mkdirSync(DIR.DB, { recursive: true })

DB = new Database(
  DB_PATH
  {
    #verbose: (sql)=>
    #  console.log chalk.gray sql
  }
)

#DB.pragma('journal_mode = WAL')

if is_new
  DB.exec readFileSync(join(DIR.FS,'db.sql'),'utf8')

export default DB
